//
//  ViewController.m
//  TestTableView
//
//  Created by Hunk on 11-12-22.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "ViewController.h"
#import "TestViewController.h"
#import "QQView.h"
#import "QQViewCell.h"

@implementation ViewController

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    QQView *qqView = [[QQView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 300.0)];
    [qqView setDataSource:self];
    [qqView setDelegate:self];
    [self.view addSubview:qqView];
    [qqView release];
    
    
    
    
//    qqView.userInteractionEnabled
//    
//    UIGestureRecognizer
    
    
//    nRow = 0;
//    nRow2 = 0;
//    
//    testTableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 460.0)
//                                                 style:UITableViewStylePlain];
//    testTableView.delegate = self;
//    testTableView.dataSource = self;
//    [self.view addSubview:testTableView];
    
    /*
    advertisementView = [[AdvertisementView alloc] initWithFrame:CGRectMake(0.0, 10.0, 320.0, 60.0)];
    [advertisementView setBackgroundColor:[UIColor clearColor]];
    advertisementView.delegate = self;
    [advertisementView setAdvertisementData:[NSArray arrayWithObjects:@"ad.png", @"ad.png", @"ad.png", @"ad.png", @"ad.png", @"ad.png", @"ad.png", @"ad.png", @"ad.png", @"ad.png", nil]];
    [self.view addSubview:advertisementView];
    
    
    page = [[PageControlView alloc] initWithFrame:CGRectMake(0.0, 50.0, 320.0, 10.0)];
    [page setBackgroundColor:[UIColor clearColor]];
    page.delegate = self;
    page.numberOfPages = 10;
    page.currentPage = 0;    
    [advertisementView addSubview:page];
    */
    
    
//    TestViewController* testViewController = [[TestViewController alloc] init];
//    [self.view addSubview:testViewController.view];
//    [testViewController release];
}


- (NSInteger)numberOfSectionsInQQView:(QQView *)qqView
{
    return 8;
}

- (NSInteger)qqView:(QQView *)qqView numberOfRowsInSection:(NSInteger)section flag:(BOOL)flag
{   
    if(flag)
    {   
        return 5;
    }
    else
    {   
        return 0;
    }
}

- (UIView *)qqView:(QQView *)qqView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320, 30)] autorelease];
    [headerView setBackgroundColor:[UIColor clearColor]];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 1.0, 280, 28)];
    [label setBackgroundColor:[UIColor clearColor]];
    [label setText:[NSString stringWithFormat:@"%d", section]];
    [headerView addSubview:label];
    [label release];

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(280.0, 10.0, 10.0, 10.0)];
    [imageView setBackgroundColor:[UIColor clearColor]];
    [imageView setImage:[UIImage imageNamed:@"next.png"]];
    
    BOOL bFlag = [[qqView.sectionDictionary objectForKey:[NSString stringWithFormat:@"SectionKey_%d", section]] boolValue];
    if(bFlag)
    {
        CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI / 2);
        
        [imageView setTransform:transform];
    }
    
    [headerView addSubview:imageView];
    [imageView release];
    
    // Line view
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 29.0, 320, 1)];
    [lineView setBackgroundColor:[UIColor grayColor]];
    [headerView addSubview:lineView];
    [lineView release];
    
    return headerView;
}

- (UITableViewCell *)qqView:(QQView *)qqView 
                  tableView:(UITableView *)tableView 
      cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"Cell";
    
    QQViewCell *cell = (QQViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if(cell == nil)
    {
        cell = [[[QQViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                  reuseIdentifier:cellIdentifier] autorelease];
    }
    
    return cell;
}

- (CGFloat)qqView:(QQView *)qqView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50.0;
}

- (CGFloat)qqView:(QQView *)qqView heightForHeaderInSection:(NSInteger)section
{
    return 30.0;
}





/*********************************************************************/
/*
- (void)advertisementView:(AdvertisementView *)advertisementView currentAdvertisement:(NSInteger)index
{
    [page setCurrentPage:index];
}

- (void)pageControlView:(PageControlView *)pageControlView didSelectPageAtIndex:(NSInteger)index
{   
    [page setCurrentPage:index];
}
*/
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
